package com.beerandjesus.common.util;

import java.util.Date;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.text.SimpleDateFormat;
import java.text.ParseException;

/**
 * User: reverend
 * Date: Oct 14, 2005
 * Time: 8:57:27 AM
 */
public class DateUtil {
    private static Calendar calendar = new GregorianCalendar();

    public static int getCalendarYear(Date date) {
        return getCalendar(date).get(Calendar.YEAR);
    }

    public static int getCalendarMonth(Date date) {
        // Calendar.MONTH is zero based..
        return getCalendar(date).get(Calendar.MONTH) + 1;
    }

    public static int getCalendarDay(Date date) {
        return getCalendar(date).get(Calendar.DAY_OF_MONTH);
    }

    private static Calendar getCalendar(Date date) {
        calendar.clear();
        calendar.setTime(date);
        return calendar;
    }

    public static Calendar getCalendarForDate(Date date) {
        Calendar cal = new GregorianCalendar();
        cal.setTime(date);
        return cal;
    }

    public static Date makeDate(int year, int month, int day) {
        SimpleDateFormat format = new SimpleDateFormat();
        Date date = null;
        try {
            date = format.parse(month + "/" + day + "/" + year + " 12:00 AM");
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
        return date;
    }
}
